package com.bleem.ds.xinshou.a02;

import com.bleem.ds.xinshou.a01.Sort;

/**
 * @author SuYanchun
 * @since 2024-08-08 下午6:49
 */
public class Comp {

    public static int[] lenRandomValueRandom(int maxLen, int maxValue) {
        int len = (int) (Math.random() * maxLen);
        int[] arr = new int[len];
        for (int i = 0; i < len; i++) {
            arr[i] = (int) (Math.random() * maxValue);
        }
        return arr;
    }

    public static boolean checkSort(int[] arr){
        if (arr.length < 2) {
            return true;
        }

        int maxValue = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (maxValue > arr[i]) {
                return false;
            }
            maxValue = arr[i];
        }
        return true;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100000; i++) {
            int[] insertionSortTestArr = lenRandomValueRandom(10, 100);
            int[] insertionSortTestArrBk = new int[insertionSortTestArr.length];
            for (int i1 = 0; i1 < insertionSortTestArr.length; i1++) {
                insertionSortTestArrBk[i1] = insertionSortTestArr[i1];
            }

            Sort.bubbleSort(insertionSortTestArr);
            if (!checkSort(insertionSortTestArr)){
                System.out.println("冒泡排序错误");
                System.out.print("    原始数组：");
                Sort.printArray(insertionSortTestArrBk);
                System.out.print("    排序数组：");
                Sort.printArray(insertionSortTestArr);
            }
        }
    }
}
